package com.yydm.servicecms.controller;


import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.yydm.commonutils.R;
import com.yydm.servicecms.entity.CrmBanner;
import com.yydm.servicecms.service.ICrmBannerService;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author yydm
 * @since 2022-07-05
 */
@RestController
@RequestMapping("/servicecms/adminbanner")
//@CrossOrigin
public class AdminBannerController {

//    后台管理系统的banner管理
    @Autowired
    private ICrmBannerService crmBannerService;

    //    分页查询banner
    @ApiOperation("分页查询banner")
    @GetMapping("/pageBanner/{page}/{limit}")
    public R pageBanner(@PathVariable("page") int page,
                        @PathVariable("limit") int limit) {
        Page<CrmBanner> pageBanner = new Page<>(page, limit);
        crmBannerService.page(pageBanner, null);
        return R.ok().data("items", pageBanner.getRecords()).data("total", pageBanner.getTotal());
    }

    //    添加
    @ApiOperation("添加banner")
    @PostMapping("/saveBanner")
    public R saveBanner(@RequestBody CrmBanner crmBanner) {
        crmBannerService.save(crmBanner);
        return R.ok();
    }

    //    修改
    @ApiOperation("修改banner")
    @PutMapping("/updateBanner")
    public R updateBanner(@RequestBody CrmBanner crmBanner) {
        crmBannerService.updateById(crmBanner);
        return R.ok();
    }

    //    删除
    @ApiOperation("删除banner")
    @DeleteMapping("/deleteBanner/{id}")
    public R deleteBanner(@PathVariable("id") int id) {
        crmBannerService.removeById(id);
        return R.ok();
    }

}
